package server.autorization.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import controllers.Autoservice;
import autoservice.api.controller.IAutoservice;


@WebServlet("/Logout")
public class Logout extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String LOGIN_PAGE = "autorizationpages/LoginPage.html";
	private IAutoservice autoservice = Autoservice.getInstance();
	private static final String LOG_OUT = "log out";
	private static final String USER = "user";
       
    
    public Logout() {
        super();
        
    }

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(false);
		autoservice.setOperation((String)session.getAttribute(USER), LOG_OUT);
      	if(session != null){
    		session.invalidate();
    	}
      	
    	response.sendRedirect(LOGIN_PAGE);
	}

}
